package com.gitee.zycra.future.job.web.controller;

import com.gitee.zycra.future.job.common.bo.CommonResult;
import com.gitee.zycra.future.job.common.param.UpdateDependenceParam;
import com.gitee.zycra.future.job.service.JobDependenceService;
import com.gitee.zycra.future.job.web.annotation.AuthCheck;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zycra
 */
@Slf4j
@RestController
@RequestMapping("/dependence")
public class JobDependenceController {

    @Autowired
    private JobDependenceService jobDependenceService;

    /**
     * 更新依赖任务
     *
     * @param updateDependenceParam 更新参数
     * @return 更新结果
     */
    @AuthCheck({"6", "7"})
    @PostMapping("/updateDependence")
    public CommonResult<String> updateDependence(@RequestBody @Validated UpdateDependenceParam updateDependenceParam) {
        return jobDependenceService.updateJobDependence(updateDependenceParam);
    }

    /**
     * 根据子调度信息ID查询父任务ID
     *
     * @param childScheduleId 子调度信息ID
     * @return 查询结果
     */
    @AuthCheck({"4", "5", "6", "7"})
    @PostMapping("/queryParentIdList")
    public CommonResult<List<Long>> queryParentIdList(@RequestParam("childScheduleId") Long childScheduleId) {
        List<Long> parentIdList = jobDependenceService.selectParentIdByChildScheduleId(childScheduleId);
        return CommonResult.success(parentIdList);
    }
}
